<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* ****************************************************************************
  NAIYUMIE KING WANG JJANG Front End Developer <naiyumie@gmail.com>
  FileType:CRLF, Encording:UTF-8, Tab&Space:4/4
  ------------------------------------------------------------------------
  공통
**************************************************************************** */

class GlobalM extends N_Model {

	/***************************************************
	 * preprocess
	 *     constructor
	 *     function
	 *     struct and global values
	 ***************************************************/
    function __construct() {
        parent::__construct();
    }


	/***************************************************
	 * c
	 ***************************************************/


	/***************************************************
	 * r
	 ***************************************************/

	# 사이드바 메인을 위한 함수
	function getSidebarMain(){
		$retVal = $this->db->query(sprintf('
			SELECT
				*
			FROM tbl_local_sidebar
			ORDER BY align ASC;'
		))->result_array();
		return $retVal;
	}

	# 사이드바 서브를 위한 함수
	function getSidebarSub($children_group){
		$retVal = $this->db->query(sprintf('
			SELECT
				*
			FROM
				tbl_local_sidebar_sub
			WHERE parent = "%s"
			ORDER BY align ASC',
			$children_group
		))->result_array();
		return $retVal;
	}

	# 멤버에 해당하는 캐릭터의 아이디를 셀렉트에서 쓸 수 있는 형태로 리턴
	function getMembersCharactersList(){
		$sql = '
			SELECT
				tbl_members.pk_uid AS members_pk_uid,
				tbl_members.uq_member_id,
				tbl_members.st_name,
				tbl_characters.pk_uid AS characters_pk_uid,
				tbl_characters.uq_name
			FROM
				tbl_members, tbl_characters
			WHERE
				tbl_characters.fk_members_pk = tbl_members.pk_uid
			ORDER BY
				tbl_members.pk_uid ASC;
		';
		$query = $this->db->query($sql);
		$result = $query->result_array();

		$membersCharactersArray = array();
		foreach($result as $key=>$val){
			$membersCharactersArray[$val['members_pk_uid']]['uq_member_id'] = $val['uq_member_id'];
			$membersCharactersArray[$val['members_pk_uid']]['st_name'] = $val['st_name'];
			$membersCharactersArray[$val['members_pk_uid']]['outgroup'] = sprintf('%s(%s)', $val['uq_member_id'], $val['st_name']);
			$membersCharactersArray[$val['members_pk_uid']]['items'][$val['characters_pk_uid']] = $val['uq_name'];
		}

		//nlog($membersCharactersArray);
		return $membersCharactersArray;
	}

	# 모든 멤버를 셀렉트에서 쓸 수 있는 형태로 리턴.
	function getMembersList(){
		$sql = '
			SELECT
				tbl_item_deposit_money_members.pk_uid,
				tbl_item_deposit_money_members.fk_members_uid,
				(SELECT tbl_members.uq_member_id FROM tbl_members WHERE tbl_item_deposit_money_members.fk_members_uid = tbl_members.pk_uid ) AS member_id,
				(SELECT tbl_members.st_name FROM tbl_members WHERE tbl_item_deposit_money_members.fk_members_uid = tbl_members.pk_uid ) AS member_name
			FROM tbl_item_deposit_money_members;
		';
		$query = $this->db->query($sql);
		$result = $query->result_array();

		$membersArray = array();
		foreach($result as $key=>$val){
			$membersArray[$val['fk_members_uid']] = sprintf('%s(%s)', $val['member_id'], $val['member_name']);
		}

		//nlog($membersArray);
		return $membersArray;
	}

	/***************************************************
	 * u
	 ***************************************************/


	/***************************************************
	 * d
	 ***************************************************/


	/***************************************************
	 * model and value objects
	 ***************************************************/

}
/* End of file */